$(document).ready(function () {


    $('#myEditor').markdownEditor({
        // Activate the preview:
        preview: true,
        // This callback is called when the user click on the preview button:
        onPreview: function (content, callback) {
            // Return the html:
            callback(marked(content));

        },
        imageUpload: true, // Activate the option
        uploadPath: '/util/uploads/img/' // Path of the server side script that receive the files
    });

    if ($("#uploadPic").attr("src").length == 0) {
        $("#uploadPic").attr("src", "/upload/minren.jpg")
    }
    $("#addNewForm").submit(function () {
        $("#content").val($('#myEditor').markdownEditor('content'));
        console.log("内容为:" + $('#myEditor').markdownEditor('content'));
        $("#picUrl").val($("#uploadPic").attr("src"));
    })

    $("#uploadPic").click(function () {
        $("#pic").click();
    })
    $("#pic").change(function () {
        var file = this.files[0]; //选择上传的文件

        var oMyForm = new FormData();

        oMyForm.append("file", file);

        var r = new FileReader();

        r.readAsDataURL(file); //Base64

        $(r).load(function () {
            console.log("change img Url" + this.result);
            $("#uploadPic").attr("src", this.result);
        });

        $.ajax({
            url: "/util/upload/pic",
            type: "POST",
            data: oMyForm,
            processData: false,  // 告诉jQuery不要去处理发送的数据
            contentType: false, // 告诉jQuery不要去设置Content-Type请求头
            success: function (responseStr) {
                console.log("sucessufl upload pic," + responseStr);
            }
        });
    })
});